﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sinacor.OMM.DumpServer;
using System.Threading;
using Sinacor.OMM.DumpEntity;
using Sinacor.OMM.DumpClient;
using Sinacor.OMM.Util;
using System.Text.RegularExpressions;
using Sinacor.OMM.Util;
using PSE.Framework.Threading;

namespace Sinacor.OMM.DumpTester
{
    public partial class formDumpTester : Form
    {

        DumperMain _dumperMain;
        Dump _dump;

        public formDumpTester()
        {
            InitializeComponent();
        }

        private void btnStartOne_Click(object sender, EventArgs e)
        {
            btnStartServer.Enabled = false;

            _dumperMain = new DumperMain();
            Thread thr = new Thread(new ThreadStart(_dumperMain.Run));
            thr.Start();

            btnStopServer.Enabled = true;
        }

        private void btnStopServer_Click(object sender, EventArgs e)
        {
            btnStopServer.Enabled = false;
            
            _dumperMain.Dispose();
            _dumperMain = null;

            btnStartServer.Enabled = true;
        }

        private void formDumpTester_FormClosed(object sender, FormClosedEventArgs e)
        {

            if(_dumperMain!=null)
                _dumperMain.Dispose();

            if (_dump != null)
                _dump.Dispose();

            Tracer.Destroy();
        }

        private void formDumpTester_FormClosing(object sender, FormClosingEventArgs e)
        {
            formDumpTester_FormClosed(sender, new FormClosedEventArgs(CloseReason.ApplicationExitCall));
        }
#region Client 01 - File 00001
        private void btnStartClient01File00001_Click(object sender, EventArgs e)
        {
            btnStartClient01File00001.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient01File00001));
            thr.Start();
            btnStopClient01File00001.Enabled = true;
        }

        private void btnStopClient01File00001_Click(object sender, EventArgs e)
        {
            btnStopClient01File00001.Enabled = false;
            _keepRunningClient01File00001 = false;
            intClient01File00001 = 0;
            btnStartClient01File00001.Enabled = true;
        }

        bool _keepRunningClient01File00001;
        int intClient01File00001 = 0;
        private void GeraLogClient01File00001()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient01File00001 = true;
            while (_keepRunningClient01File00001)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client01";
                dumpTraceData.FileName = "File00001";
                dumpTraceData.DataToDump = "Log Número:[" + intClient01File00001.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient01File00001++;
                Sleeper.Sleep(1, IsRunningClient01File00001);
            }
        }

        private bool IsRunningClient01File00001()
        {
            return _keepRunningClient01File00001;
        }
#endregion

#region Client 01 - File 01000

        private void btnStartClient01File01000_Click(object sender, EventArgs e)
        {
            btnStartClient01File01000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient01File01000));
            thr.Start();
            btnStopClient01File01000.Enabled = true;
        }

        private void btnStopClient01File01000_Click(object sender, EventArgs e)
        {
            btnStopClient01File01000.Enabled = false;
            _keepRunningClient01File01000 = false;
            intClient01File00001 = 0;
            btnStartClient01File01000.Enabled = true;
        }

        bool _keepRunningClient01File01000;
        int intClient01File01000 = 0;
        private void GeraLogClient01File01000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient01File01000 = true;
            while (_keepRunningClient01File01000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client01";
                dumpTraceData.FileName = "File01000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient01File01000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient01File01000++;
                Sleeper.Sleep(1000, IsRunningClient01File01000);
            }
        }

        private bool IsRunningClient01File01000()
        {
            return _keepRunningClient01File01000;
        }
#endregion

#region Client 01 - File 10000

        private void btnStartClient01File10000_Click(object sender, EventArgs e)
        {
            btnStartClient01File10000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient01File10000));
            thr.Start();
            btnStopClient01File10000.Enabled = true;
        }

        private void btnStopClient01File10000_Click(object sender, EventArgs e)
        {
            btnStopClient01File10000.Enabled = false;
            _keepRunningClient01File10000 = false;
            intClient01File00001 = 0;
            btnStartClient01File10000.Enabled = true;
        }

        bool _keepRunningClient01File10000;
        int intClient01File10000 = 0;
        private void GeraLogClient01File10000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient01File10000 = true;
            while (_keepRunningClient01File10000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client01";
                dumpTraceData.FileName = "File10000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient01File10000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient01File10000++;
                Sleeper.Sleep(10000, IsRunningClient01File10000);
            }
        }

        private bool IsRunningClient01File10000()
        {
            return _keepRunningClient01File10000;
        }
#endregion

#region Client 01 - File 70000

        private void btnStartClient01File70000_Click(object sender, EventArgs e)
        {
            btnStartClient01File70000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient01File70000));
            thr.Start();
            btnStopClient01File70000.Enabled = true;
        }

        private void btnStopClient01File70000_Click(object sender, EventArgs e)
        {
            btnStopClient01File70000.Enabled = false;
            _keepRunningClient01File70000 = false;
            intClient01File00001 = 0;
            btnStartClient01File70000.Enabled = true;
        }

        bool _keepRunningClient01File70000;
        int intClient01File70000 = 0;
        private void GeraLogClient01File70000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient01File70000 = true;
            while (_keepRunningClient01File70000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client01";
                dumpTraceData.FileName = "File70000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient01File70000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient01File70000++;
                Sleeper.Sleep(70000, IsRunningClient01File70000);
            }
        }

        private bool IsRunningClient01File70000()
        {
            return _keepRunningClient01File70000;
        }
#endregion

#region Client 02 - File 00001
        private void btnStartClient02File00001_Click(object sender, EventArgs e)
        {
            btnStartClient02File00001.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient02File00001));
            thr.Start();
            btnStopClient02File00001.Enabled = true;
        }

        private void btnStopClient02File00001_Click(object sender, EventArgs e)
        {
            btnStopClient02File00001.Enabled = false;
            _keepRunningClient02File00001 = false;
            intClient02File00001 = 0;
            btnStartClient02File00001.Enabled = true;
        }

        bool _keepRunningClient02File00001;
        int intClient02File00001 = 0;
        private void GeraLogClient02File00001()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient02File00001 = true;
            while (_keepRunningClient02File00001)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client02";
                dumpTraceData.FileName = "File00001";
                dumpTraceData.DataToDump = "Log Número:[" + intClient02File00001.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient02File00001++;
                Sleeper.Sleep(1, IsRunningClient02File00001);
            }
        }

        private bool IsRunningClient02File00001()
        {
            return _keepRunningClient02File00001;
        }
        #endregion

#region Client 02 - File 01000

        private void btnStartClient02File01000_Click(object sender, EventArgs e)
        {
            btnStartClient02File01000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient02File01000));
            thr.Start();
            btnStopClient02File01000.Enabled = true;
        }

        private void btnStopClient02File01000_Click(object sender, EventArgs e)
        {
            btnStopClient02File01000.Enabled = false;
            _keepRunningClient02File01000 = false;
            intClient02File00001 = 0;
            btnStartClient02File01000.Enabled = true;
        }

        bool _keepRunningClient02File01000;
        int intClient02File01000 = 0;
        private void GeraLogClient02File01000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient02File01000 = true;
            while (_keepRunningClient02File01000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client02";
                dumpTraceData.FileName = "File01000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient02File01000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient02File01000++;
                Sleeper.Sleep(1000, IsRunningClient02File01000);
            }
        }

        private bool IsRunningClient02File01000()
        {
            return _keepRunningClient02File01000;
        }
        #endregion

#region Client 02 - File 10000

        private void btnStartClient02File10000_Click(object sender, EventArgs e)
        {
            btnStartClient02File10000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient02File10000));
            thr.Start();
            btnStopClient02File10000.Enabled = true;
        }

        private void btnStopClient02File10000_Click(object sender, EventArgs e)
        {
            btnStopClient02File10000.Enabled = false;
            _keepRunningClient02File10000 = false;
            intClient02File00001 = 0;
            btnStartClient02File10000.Enabled = true;
        }

        bool _keepRunningClient02File10000;
        int intClient02File10000 = 0;
        private void GeraLogClient02File10000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient02File10000 = true;
            while (_keepRunningClient02File10000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client02";
                dumpTraceData.FileName = "File10000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient02File10000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient02File10000++;
                Sleeper.Sleep(10000, IsRunningClient02File10000);
            }
        }

        private bool IsRunningClient02File10000()
        {
            return _keepRunningClient02File10000;
        }
        #endregion

#region Client 02 - File 70000

        private void btnStartClient02File70000_Click(object sender, EventArgs e)
        {
            btnStartClient02File70000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient02File70000));
            thr.Start();
            btnStopClient02File70000.Enabled = true;
        }

        private void btnStopClient02File70000_Click(object sender, EventArgs e)
        {
            btnStopClient02File70000.Enabled = false;
            _keepRunningClient02File70000 = false;
            intClient02File00001 = 0;
            btnStartClient02File70000.Enabled = true;
        }

        bool _keepRunningClient02File70000;
        int intClient02File70000 = 0;
        private void GeraLogClient02File70000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient02File70000 = true;
            while (_keepRunningClient02File70000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client02";
                dumpTraceData.FileName = "File70000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient02File70000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient02File70000++;
                Sleeper.Sleep(70000, IsRunningClient02File70000);
            }
        }

        private bool IsRunningClient02File70000()
        {
            return _keepRunningClient02File70000;
        }
        #endregion

#region Client 03 - File 00001
        private void btnStartClient03File00001_Click(object sender, EventArgs e)
        {
            btnStartClient03File00001.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient03File00001));
            thr.Start();
            btnStopClient03File00001.Enabled = true;
        }

        private void btnStopClient03File00001_Click(object sender, EventArgs e)
        {
            btnStopClient03File00001.Enabled = false;
            _keepRunningClient03File00001 = false;
            intClient03File00001 = 0;
            btnStartClient03File00001.Enabled = true;
        }

        bool _keepRunningClient03File00001;
        int intClient03File00001 = 0;
        private void GeraLogClient03File00001()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient03File00001 = true;
            while (_keepRunningClient03File00001)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client03";
                dumpTraceData.FileName = "File00001";
                dumpTraceData.DataToDump = "Log Número:[" + intClient03File00001.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient03File00001++;
                Sleeper.Sleep(1, IsRunningClient03File00001);
            }
        }

        private bool IsRunningClient03File00001()
        {
            return _keepRunningClient03File00001;
        }
        #endregion

#region Client 03 - File 01000

        private void btnStartClient03File01000_Click(object sender, EventArgs e)
        {
            btnStartClient03File01000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient03File01000));
            thr.Start();
            btnStopClient03File01000.Enabled = true;
        }

        private void btnStopClient03File01000_Click(object sender, EventArgs e)
        {
            btnStopClient03File01000.Enabled = false;
            _keepRunningClient03File01000 = false;
            intClient03File00001 = 0;
            btnStartClient03File01000.Enabled = true;
        }

        bool _keepRunningClient03File01000;
        int intClient03File01000 = 0;
        private void GeraLogClient03File01000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient03File01000 = true;
            while (_keepRunningClient03File01000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client03";
                dumpTraceData.FileName = "File01000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient03File01000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient03File01000++;
                Sleeper.Sleep(1000, IsRunningClient03File01000);
            }
        }

        private bool IsRunningClient03File01000()
        {
            return _keepRunningClient03File01000;
        }
        #endregion

#region Client 03 - File 10000

        private void btnStartClient03File10000_Click(object sender, EventArgs e)
        {
            btnStartClient03File10000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient03File10000));
            thr.Start();
            btnStopClient03File10000.Enabled = true;
        }

        private void btnStopClient03File10000_Click(object sender, EventArgs e)
        {
            btnStopClient03File10000.Enabled = false;
            _keepRunningClient03File10000 = false;
            intClient03File00001 = 0;
            btnStartClient03File10000.Enabled = true;
        }

        bool _keepRunningClient03File10000;
        int intClient03File10000 = 0;
        private void GeraLogClient03File10000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient03File10000 = true;
            while (_keepRunningClient03File10000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client03";
                dumpTraceData.FileName = "File10000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient03File10000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient03File10000++;
                Sleeper.Sleep(10000, IsRunningClient03File10000);
            }
        }

        private bool IsRunningClient03File10000()
        {
            return _keepRunningClient03File10000;
        }
        #endregion

#region Client 03 - File 70000

        private void btnStartClient03File70000_Click(object sender, EventArgs e)
        {
            btnStartClient03File70000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient03File70000));
            thr.Start();
            btnStopClient03File70000.Enabled = true;
        }

        private void btnStopClient03File70000_Click(object sender, EventArgs e)
        {
            btnStopClient03File70000.Enabled = false;
            _keepRunningClient03File70000 = false;
            intClient03File00001 = 0;
            btnStartClient03File70000.Enabled = true;
        }

        bool _keepRunningClient03File70000;
        int intClient03File70000 = 0;
        private void GeraLogClient03File70000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient03File70000 = true;
            while (_keepRunningClient03File70000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client03";
                dumpTraceData.FileName = "File70000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient03File70000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient03File70000++;
                Sleeper.Sleep(70000, IsRunningClient03File70000);
            }
        }

        private bool IsRunningClient03File70000()
        {
            return _keepRunningClient03File70000;
        }
        #endregion

#region Client 04 - File 00000
        private void btnStartClient04File00000_Click(object sender, EventArgs e)
        {
            btnStartClient04File00000.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient04File00000));
            thr.Start();
            btnStopClient04File00000.Enabled = true;
        }

        private void btnStopClient04File00000_Click(object sender, EventArgs e)
        {
            btnStopClient04File00000.Enabled = false;
            _keepRunningClient04File00000 = false;
            intClient04File00000 = 0;
            btnStartClient04File00000.Enabled = true;
        }

        bool _keepRunningClient04File00000;
        int intClient04File00000 = 0;
        private void GeraLogClient04File00000()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient04File00000 = true;
            while (_keepRunningClient04File00000)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client04";
                dumpTraceData.FileName = "File00000";
                dumpTraceData.DataToDump = "Log Número:[" + intClient04File00000.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient04File00000++;
            }
        }

        private bool IsRunningClient04File00000()
        {
            return _keepRunningClient04File00000;
        }
        #endregion

#region Client 05 - File 00005

        private void btnStartClient05File00005_Click(object sender, EventArgs e)
        {
            btnStartClient05File00005.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient05File00005));
            thr.Start();
            btnStopClient05File00005.Enabled = true;
        }

        private void btnStopClient05File00005_Click(object sender, EventArgs e)
        {
            btnStopClient05File00005.Enabled = false;
            _keepRunningClient05File00005 = false;
            intClient05File00005 = 0;
            btnStartClient05File00005.Enabled = true;
        }

        bool _keepRunningClient05File00005;
        int intClient05File00005 = 0;
        private void GeraLogClient05File00005()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient05File00005 = true;
            while (_keepRunningClient05File00005)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client05";
                dumpTraceData.FileName = "File00005";
                dumpTraceData.DataToDump = "Log Número:[" + intClient05File00005.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient05File00005++;
                Sleeper.Sleep(5, IsRunningClient05File00005);
            }
        }

        private bool IsRunningClient05File00005()
        {
            return _keepRunningClient05File00005;
        }
        #endregion

#region Client 06 - File 00010

        private void btnStartClient06File00010_Click(object sender, EventArgs e)
        {
            btnStartClient06File00010.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient06File00010));
            thr.Start();
            btnStopClient06File00010.Enabled = true;
        }

        private void btnStopClient06File00010_Click(object sender, EventArgs e)
        {
            btnStopClient06File00010.Enabled = false;
            _keepRunningClient06File00010 = false;
            intClient06File00010 = 0;
            btnStartClient06File00010.Enabled = true;
        }

        bool _keepRunningClient06File00010;
        int intClient06File00010 = 0;
        private void GeraLogClient06File00010()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient06File00010 = true;
            while (_keepRunningClient06File00010)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client06";
                dumpTraceData.FileName = "File00010";
                dumpTraceData.DataToDump = "Log Número:[" + intClient06File00010.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient06File00010++;
                Sleeper.Sleep(50, IsRunningClient06File00010);
            }
        }

        private bool IsRunningClient06File00010()
        {
            return _keepRunningClient06File00010;
        }
        #endregion

#region Client 07 - File 00100

        private void btnStartClient07File00100_Click(object sender, EventArgs e)
        {
            btnStartClient07File00100.Enabled = false;
            Thread thr = new Thread(new ThreadStart(GeraLogClient07File00100));
            thr.Start();
            btnStopClient07File00100.Enabled = true;
        }

        private void btnStopClient07File00100_Click(object sender, EventArgs e)
        {
            btnStopClient07File00100.Enabled = false;
            _keepRunningClient07File00100 = false;
            intClient07File00100 = 0;
            btnStartClient07File00100.Enabled = true;
        }

        bool _keepRunningClient07File00100;
        int intClient07File00100 = 0;
        private void GeraLogClient07File00100()
        {
            _dump = Dump.GetInstance();
            _keepRunningClient07File00100 = true;
            while (_keepRunningClient07File00100)
            {
                DumpTraceData dumpTraceData = new DumpTraceData();
                dumpTraceData.FolderName = "Client07";
                dumpTraceData.FileName = "File00100";
                dumpTraceData.DataToDump = "Log Número:[" + intClient07File00100.ToString() + "]";
                _dump.Send(dumpTraceData);
                intClient07File00100++;
                Sleeper.Sleep(00100, IsRunningClient07File00100);
            }
        }

        private bool IsRunningClient07File00100()
        {
            return _keepRunningClient07File00100;
        }
        #endregion

        TraceWriter _tracer1 = Tracer.GetInstance("C:\\diretorio01", "arquivo01");
        TraceWriter _tracer2 = Tracer.GetInstance("\\diretorio01", "arquivo02");
        TraceWriter _tracer3 = Tracer.GetInstance("diretorio01\\", "arquivo03");
        TraceWriter _tracer4 = Tracer.GetInstance("\\diretorio02\\", "arquivo01");
        TraceWriter _tracer5 = Tracer.GetInstance("C:\\diretorio02\\", "arquivo02");
        TraceWriter _tracer6 = Tracer.GetInstance("diretorio02", "arquivo03");

        private void btnTeste_Click(object sender, EventArgs e)
        {
 

            Thread thr1 = new Thread(new ThreadStart(TesteTrace01));
            thr1.Start();

            //bool ok;
            
            //ok = ValidaDadosBasicos("Parente", "Marco");

            //MessageBox.Show(ok.ToString());

            //ok = ValidaDadosBasicos("Parente01", "Marco01");

            //MessageBox.Show(ok.ToString());

            //ok = ValidaDadosBasicos(@"Parente\Fulano", @"Marco\Fulano");

            //MessageBox.Show(ok.ToString());


            //Compara();
            //MessageBox.Show(ComparaPerformance());
        }

        private void TesteTrace01()
        {
            for(int idx = 0; idx < 50000; idx++)
            {
                _tracer1.Trace("Teste - " + idx);
                _tracer2.Trace("Teste - " + idx);
                _tracer3.Trace("Teste - " + idx);
                _tracer4.Trace("Teste - " + idx);
                _tracer5.Trace("Teste - " + idx);
                _tracer6.Trace("Teste - " + idx);
                _tracer1.Trace("Opcional Teste - " + idx, TraceType.Optional);
                _tracer2.Trace("Opcional Teste - " + idx, TraceType.Optional);
                _tracer3.Trace("Opcional Teste - " + idx, TraceType.Optional);
                _tracer4.Trace("Opcional Teste - " + idx, TraceType.Optional);
                _tracer5.Trace("Opcional Teste - " + idx, TraceType.Optional);
                _tracer6.Trace("Opcional Teste - " + idx, TraceType.Optional);
            }
        }

        public bool ValidaDadosBasicos(string foldername, string filename)
        {
            Regex regex = new Regex(@"[^a-zA-Z0-9]");

            if (foldername.Trim().Length <= 0)
                return false;

            if (regex.Match(foldername).Success)
                return false;

            if (filename.Trim().Length <= 0)
                return false;

            if (regex.Match(filename).Success)
                return false;

            return true;
        }

        private string ComparaPerformance()
        {
            string ret;
            string MSG_ID_OLD;
            string MSG_ID_NEW;
            DateTime dtIni;
            DateTime dtFim; 

            dtIni = DateTime.Now;

            for (int x = 0; x < 1000000; x++)
            {
                MSG_ID_OLD = "20091031A0000000001";
                MSG_ID_NEW = "20091031A0000000002";

                if( getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW)){}

                MSG_ID_OLD = "20091031A0000000001";
                MSG_ID_NEW = "20091101A0000000001";

                if (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW)) { }

                MSG_ID_OLD = "20091031A0000000001";
                MSG_ID_NEW = "20091031B0000000001";

                if (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW)) { }

                MSG_ID_OLD = "20091031A0000000099";
                MSG_ID_NEW = "20091031B0000000001";

                if (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW)) { }
            }
            dtFim = DateTime.Now;

            ret = "Tempo 2" + dtFim.Subtract(dtIni).TotalSeconds.ToString() + "\r\n";

            return ret;
        }


        private void Compara()
        {
            string MSG_ID_OLD;
            string MSG_ID_NEW;

            MSG_ID_OLD = "20091031A0000000001";
            MSG_ID_NEW = "20091031A0000000002";

            MessageBox.Show("Entre getNumber: \r\n" + MSG_ID_OLD + "\r\n" + MSG_ID_NEW + "\r\n o maior é: " + (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW) ? MSG_ID_OLD : MSG_ID_NEW));

            MSG_ID_OLD = "20091031A0000000001";
            MSG_ID_NEW = "20091101A0000000001";

            MessageBox.Show("Entre getNumber: \r\n" + MSG_ID_OLD + "\r\n" + MSG_ID_NEW + "\r\n o maior é: " + (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW) ? MSG_ID_OLD : MSG_ID_NEW));

            MSG_ID_OLD = "20091031A0000000001";
            MSG_ID_NEW = "20091031B0000000001";

            MessageBox.Show("Entre getNumber: \r\n" + MSG_ID_OLD + "\r\n" + MSG_ID_NEW + "\r\n o maior é: " + (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW) ? MSG_ID_OLD : MSG_ID_NEW));

            MSG_ID_OLD = "20091031A0000000099";
            MSG_ID_NEW = "20091031B0000000001";

            MessageBox.Show("Entre getNumber: \r\n" + MSG_ID_OLD + "\r\n" + MSG_ID_NEW + "\r\n o maior é: " + (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW) ? MSG_ID_OLD : MSG_ID_NEW));

            MSG_ID_OLD = "20091031A9999999999";
            MSG_ID_NEW = "20091031B0000000001";

            MessageBox.Show("Entre getNumber: \r\n" + MSG_ID_OLD + "\r\n" + MSG_ID_NEW + "\r\n o maior é: " + (getNumber(MSG_ID_OLD) > getNumber(MSG_ID_NEW) ? MSG_ID_OLD : MSG_ID_NEW));

        }



        private Int64 getNumber(string msgId)
        {
            return Convert.ToInt64(string.Concat(Char.ConvertToUtf32(msgId.ToUpper(), 8), msgId.Substring(9)));
        }

        private void button1_Click(object sender, EventArgs e)
        {
           TraceWriter tw  = Tracer.GetInstance("Teste Trace by Dump", "Super Teste");

           for (int idx = 0; idx < 10; idx++)
           {
               tw.Trace("vai " + idx);
           }

           Tracer.Destroy();
        }

    }
}
